#include "utility.h"

#include <windows.h>

namespace util{

    // Fps limiter: permet de limiter le nombre d'executions de frames de la fonction
    fps_limiter::fps_limiter():
        frame_duration( UTIL_DFT_FPS_LIMITER ),
        last_cron( clock() ) {}
    void fps_limiter::exec(){
        clock_t stack = clock() - last_cron;
        clock_t frameTimeLimit = CLOCKS_PER_SEC/frame_duration;
        if( stack < frameTimeLimit ){
            sleep( frameTimeLimit - stack );
        }
        last_cron = clock();
    }
    void fps_limiter::setLimit(unsigned char val){
        frame_duration = val;
    }
    unsigned char fps_limiter::getLimit(){
        return frame_duration;
    }

}
